//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - lower
//===================================================================================


namespace App.Data.SqlServer.Repositories {
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using App.Model;

    public class EducationRepository : BaseRepository, IEducationRepository {
        public EducationRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork) {
        }
        public void Create(Education education) {
            this.GetDbSet<Education>().Add(education);
            this.UnitOfWork.SaveChanges();
        }

        public Education GetEducation(Guid educationId) {
            return this.GetDbSet<Education>()
                .Where(c => c.Id == educationId)
                .Single();
        }

        public void Update(Education updatedEducation) {
            this.GetDbSet<Education>().Attach(updatedEducation);
            this.SetEntityState(updatedEducation, updatedEducation.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid educationId) {
            Education EducationToDelete = this.GetEducation(educationId);
            this.GetDbSet<Education>().Remove(EducationToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IQueryable<Education> Find()
        {
            return this.GetDbSet<Education>();
        }

        public IQueryable<Education> GetAll()
        {
            return this.GetDbSet<Education>();
        }
    }
}
